/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts;

import com.sun.faces.application.ApplicationResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Application;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author davidcabrera
 */
public class AltaUsuarioForm extends org.apache.struts.action.ActionForm {

    private Integer idUsuario;
    private String nombre;
    private String email;
    private String repEmail;
    private String pass;
    private String repPass;
    private boolean administrador;

    public AltaUsuarioForm() {
    }

    public AltaUsuarioForm(boolean administrador) {
        this.administrador = administrador;
    }
    
    public AltaUsuarioForm(String nombre, String email, String pass, boolean administrador) {
        this.nombre = nombre;
        this.email = email;
        this.pass = pass;
        this.administrador = administrador;
    }

    public String getRepEmail() {
        return repEmail;
    }

    public void setRepEmail(String repEmail) {
        this.repEmail = repEmail;
    }

    public String getRepPass() {
        return repPass;
    }

    public void setRepPass(String repPass) {
        this.repPass = repPass;
    }

    public Integer getIdUsuario() {
        return this.idUsuario;
    }

    public void setIdUsuario(Integer idUsuario) {
        this.idUsuario = idUsuario;
    }

    public String getNombre() {
        return this.nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPass() {
        return this.pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public boolean isAdministrador() {
        return this.administrador;
    }

    public void setAdministrador(boolean administrador) {
        this.administrador = administrador;
    }

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (this.getNombre() == null || this.getNombre().length() < 1 || getNombre()=="Nombre") {
            errors.add("nombre", new ActionMessage("error.name.required"));
        }  if (this.getEmail() == null || this.getEmail().length() < 1 || getEmail()=="Email") {
            errors.add("email", new ActionMessage("error.email.required"));
        } if (!this.getEmail().contains("@")) {
            errors.add("email", new ActionMessage("error.email.contain"));
        } if (this.getPass() == null || this.getPass().length() < 1 || getPass()=="Password") {
            errors.add("pass", new ActionMessage("error.pass.required"));
        }if(this.getPass().length()<4){
            errors.add("pass", new ActionMessage("error.pass.length"));
        }if (!this.getEmail().equals(this.getRepEmail())) {
            errors.add("email", new ActionMessage("error.email.equal"));
        }if (!this.getPass().equals(this.getRepPass())) {
            errors.add("pass", new ActionMessage("error.pass.equal"));
        }
        return errors;
    }
}
